package com.marvels.approve.process.consum.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.marvels.approve.process.consum.ConsumerUserApi;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.externalservice.service.ShortLinkInfoService;

@Component
public class ConsumerUserApiImpl implements ConsumerUserApi{
	
	@Autowired
	private ShortLinkInfoService shortLinkService;
	
	@Override
	public String insert(String longUrl,String loanId) {
		try {
			String result = shortLinkService.insert(longUrl, loanId);
			MarvelsLogUtil.getInstance().info("ConsumerUserApi.insert direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ConsumerUserApi.insert error", e);
			return null;
		}
	}

	@Override
	public String selectLongUrlByShortUrl(String shortUrl) {
		try {
			String result = shortLinkService.selectLongUrlByShortUrl(shortUrl);
			MarvelsLogUtil.getInstance().info("ConsumerUserApi.selectLongUrlByShortUrl direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ConsumerUserApi.selectLongUrlByShortUrl error", e);
			return null;
		}
	}

	@Override
	public void deleteByloanId(String loanId) {
		try {
			shortLinkService.deleteByloanId(loanId);
			MarvelsLogUtil.getInstance().info("ConsumerUserApi.deleteByloanId direct call success!");
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ConsumerUserApi.deleteByloanId error", e);
		}
	}

	@Override
	public String queryLongUrl(String loanId) {
		try {
			String result = shortLinkService.queryLongUrl(loanId);
			MarvelsLogUtil.getInstance().info("ConsumerUserApi.queryLongUrl direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ConsumerUserApi.queryLongUrl error", e);
			return null;
		}
	}

}
